<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
	<!-- // <script src="http://code.jquery.com/jquery-latest.js"></script> -->
	<script type="text/javascript" src="../jquery-2.1.4.js"></script>
	<script type="text/javascript">
	
		function Deferred() {
			var callbacks = [],
				pending = 'unfulfilled', 
				_value;
			return {
				resolve: function(value) {
					if(pending == 'unfulfilled'){
						for (var i = 0, ii = callbacks.length; i < ii; i++) {
							var callback = callbacks[i];
							callback(value);
						}
						_value = value
						pending = 'fulfilled' 
						callbacks = undefined;						
					}
				},
				then: function(callback) {
					if (pending == 'unfulfilled') { 
						callbacks.push(callback);
					} else {
						callback(_value);
					}
				}
			}
		};

		var Task = function () {
		    var result = Deferred();
		    setTimeout(function () {
		        result.resolve('Aaron');
		    }, 1000);
		    return result;
		};

		Task().then(function(value){
			alert(value) //Aaron
		});


	</script>
</head>
<body>

</body>
</html>